#!/usr/bin/python
# -*- coding:utf-8 -*-

import locale
import sys
import optparse

reload(sys)
sys.setdefaultencoding('utf-8') # for BeautifulSoup
import BeautifulSoup

import PageOpener
import GetWallpaperLog

CONSOLE_ENCODE = locale.getpreferredencoding()

def getImageUrl(sourceUrl, logger, proxy=None) :
    pageOpener = PageOpener.PageOpener(logger=logger,
                                       proxy=proxy,
                                       console_encode=CONSOLE_ENCODE)
    html = pageOpener.open(fullurl=sourceUrl)
    soup = BeautifulSoup.BeautifulSoup(html)
    images = soup.findAll(name = 'img')
    if images != None :
        return images[0]['src']
    else :
        return None
